//
//  CGQdetailHeadView.swift
//  SheYangBigData
//
//  Created by 叁拾叁 on 2021/4/7.
//  Copyright © 2021 叁拾叁. All rights reserved.
//

import UIKit

class CGQdetailHeadView: UICollectionReusableView {

    var currentVC: UIViewController!
    public var passParamsClosure: ((Any) -> Void)?

    let title: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 14.autoBoldFontSize()
        v.numberOfLines = 0
        v.text = "设备离线"
        return v
    }()
    
    let pic: UIImageView = {
        let v: UIImageView = UIImageView()
        v.sy_name("detail_zaixian")
        return v
    }()
    
    let biaohao: CGQshebeiView = {
        let v = CGQshebeiView()
        v.title.text = "设备编号："
        v.num.text = "设备编号："
        return v
    }()
    
    let mingcheng: CGQshebeiView = {
        let v = CGQshebeiView()
        v.title.text = "设备名称："
        v.num.text = "设备编号："
        return v
    }()
    
    let leixing: CGQshebeiView = {
        let v = CGQshebeiView()
        v.title.text = "设备类型："
        v.num.text = "设备编号："
        return v
    }()
    
    let xieyi: CGQshebeiView = {
        let v = CGQshebeiView()
        v.title.text = "解析协议："
        v.num.text = "设备编号："
        return v
    }()
    
    let duankou: CGQshebeiView = {
        let v = CGQshebeiView()
        v.title.text = "采集端口："
        v.num.text = "设备编号："
        return v
    }()
    
    var bgView: UIView = {
        let v = UIView()
        v.backgroundColor = Constant.bgViewColor
        return v
    }()
    
    var sepView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(hex: 0x0782FF)
        return v
    }()
    
    let cgqTitle: UILabel = {
        let v = UILabel()
        v.text = "传感器列表"
        v.font = 16.autoBoldFontSize()
        v.textColor = UIColor(hex: 0x333333)
        return v
    }()
    
    var kai: UIButton = {
        let v = UIButton()
        v.setTitle("启用", for: .normal)
        v.setTitleColor(UIColor.white, for: .selected)
        v.setTitleColor(UIColor(hex: 0x08CC81), for: .normal)
        v.titleLabel?.font = 13.autoFontSize()
        v.setBackgroundImage(UIImage(named: "detail_qiyong_select"), for: .selected)
        v.setBackgroundImage(UIImage(named: "detail_qiyong"), for: .normal)
        v.isSelected = true
        return v
    }()
    
    var guan: UIButton = {
        let v = UIButton()
        v.setTitle("禁用", for: .normal)
        v.setTitleColor(UIColor(hex: 0x08CC81), for: .normal)
        v.setTitleColor(UIColor.white, for: .selected)
        v.titleLabel?.font = 13.autoFontSize()
        v.setBackgroundImage(UIImage(named: "detail_jinyong"), for: .normal)
        v.setBackgroundImage(UIImage(named: "detail_jinyong_select"), for: .selected)
        return v
    }()
    
    var xiangmuBt: UIButton = {
        let v = UIButton()
        return v
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func configure(model: CGQshebeiinfoModel) {
        title.text = model.appName
        if model.isOnline == 1  {
            pic.sy_name("detail_zaixian")

            
        }else{
            pic.sy_name("shebei_lixian")

        }
        biaohao.num.text = model.deviceId
        mingcheng.num.text = model.deviceName
        leixing.num.text = model.protocolDeviceTypeName
        xieyi.num.text = model.protocolName
        duankou.num.text = model.portName
        
    
        kai.addAction {[weak self] in
            if let `self` = self {
//                let vc = CGQshebeiInfoVC(id: "1")
//                self.currentVC.sy_push(vc)
                self.passParamsClosure?(1)
            }
        }
        
        guan.addAction {[weak self] in
            if let `self` = self {
//                let vc = CGQshebeiInfoVC(id: "1")
//                self.currentVC.sy_push(vc)
                self.passParamsClosure?(0)

            }
        }
    }
    
    func initViews() {
        
        self.backgroundColor = .white
        addSubview(pic)
        addSubview(title)
        addSubview(biaohao)
        
        addSubview(mingcheng)
        addSubview(leixing)
        addSubview(xieyi)
        addSubview(duankou)
        addSubview(duankou)
        
        addSubview(bgView)
        addSubview(sepView)
        addSubview(cgqTitle)
        addSubview(kai)
        addSubview(guan)
//        addSubview(xiangmuBt)
        
   
        title.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(18.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(55))
            make.right.equalToSuperview().offset(autoWidth(-12.0))
        }
        pic.snp.makeConstraints { (make) in
            make.centerY.equalTo(title.snp.centerY)
            make.left.equalToSuperview()
            make.width.equalTo(48.autoWidth())
            make.height.equalTo(24.autoWidth())
        }
       
        biaohao.snp.makeConstraints { (make) in
        
            make.top.equalTo(title.snp.bottom).offset(18.autoWidth())
            make.left.equalToSuperview().offset(10.autoWidth())
            make.right.equalToSuperview().offset(-10.autoWidth())
            make.height.equalTo(13.autoWidth())
        }
        
        mingcheng.snp.makeConstraints { (make) in
            make.top.equalTo(biaohao.snp.bottom).offset(12.autoWidth())
            make.left.equalToSuperview().offset(10.autoWidth())
            make.right.equalToSuperview().offset(-10.autoWidth())
            make.height.equalTo(13.autoWidth())
        }
        
        leixing.snp.makeConstraints { (make) in
            make.top.equalTo(mingcheng.snp.bottom).offset(12.autoWidth())
            make.left.equalToSuperview().offset(10.autoWidth())
            make.right.equalToSuperview().offset(-10.autoWidth())
            make.height.equalTo(13.autoWidth())
        }
        
        xieyi.snp.makeConstraints { (make) in
            make.top.equalTo(leixing.snp.bottom).offset(12.autoWidth())
            make.left.equalToSuperview().offset(10.autoWidth())
            make.right.equalToSuperview().offset(-10.autoWidth())
            make.height.equalTo(13.autoWidth())
        }
        
        duankou.snp.makeConstraints { (make) in
            make.top.equalTo(xieyi.snp.bottom).offset(12.autoWidth())
            make.left.equalToSuperview().offset(10.autoWidth())
            make.right.equalToSuperview().offset(-10.autoWidth())
            make.height.equalTo(13.autoWidth())
            
        }
        bgView.snp.makeConstraints { (make) in
            make.top.equalTo(duankou.snp.bottom).offset(12.autoWidth())
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(45.autoWidth())
        }
        sepView.snp.makeConstraints { (make) in
//            make.top.equalTo(duankou.snp.bottom).offset(12.autoWidth())
            make.centerY.equalTo(bgView.snp.centerY)
            make.left.equalToSuperview()
            make.width.equalTo(2.5.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        cgqTitle.snp.makeConstraints { (make) in
            make.top.equalTo(duankou.snp.bottom).offset(12.autoWidth())
            make.left.equalToSuperview().offset(8.autoWidth())
            make.height.equalTo(45.autoWidth())
        }
        kai.snp.makeConstraints { (make) in
            make.centerY.equalTo(bgView.snp.centerY)
            make.right.equalToSuperview().offset(-60.autoWidth())
            make.width.equalTo(50.autoWidth())
            make.height.equalTo(25.autoWidth())
        }
        guan.snp.makeConstraints { (make) in
            make.centerY.equalTo(bgView.snp.centerY)
            make.right.equalToSuperview().offset(-10.autoWidth())
            make.width.equalTo(50.autoWidth())
            make.height.equalTo(25.autoWidth())
        }
//        xiangmuBt.snp.makeConstraints { (make) in
//            make.edges.equalToSuperview()
//        }
    }
}
